package com.wjk.kylin.mall.auth.feign.fallback;

import com.wjk.kylin.mall.auth.feign.AdminFeignService;
import com.wjk.kylin.mall.common.core.bo.admin.OAuth2ClientBO;
import com.wjk.kylin.mall.common.core.bo.admin.UserNameBO;
import com.wjk.kylin.mall.common.core.dto.admin.OAuth2ClientInDTO;
import com.wjk.kylin.mall.common.core.dto.admin.UserIdInDTO;
import com.wjk.kylin.mall.common.core.dto.admin.UserNameInDTO;
import com.wjk.kylin.mall.common.core.dto.base.DataOutDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 调用方熔断保护 Factory
 * 可以打印异常等处理
 */
@Slf4j
@Service
public class AdminFeignServiceFallbackFactory implements FallbackFactory<AdminFeignService> {

    @Override
    public AdminFeignService create(Throwable throwable) {
        return new AdminFeignService() {

            @Override
            public DataOutDTO<UserNameBO> loadUserByUsername(UserNameInDTO inDTO) {
                log.error("mall-admin,loadUserByUsername 熔断异常：{}", throwable.getMessage());
                return null;
            }

            @Override
            public DataOutDTO<List<String>> getMenuPermsByUser(UserIdInDTO inDTO) {
                log.error("mall-admin,getMenuPermsByUser 熔断异常：{}", throwable.getMessage());
                return null;
            }

            @Override
            public DataOutDTO<List<Long>> getRoleIdByUserId(UserIdInDTO inDTO) {
                log.error("mall-admin,getRoleIdByUserId 熔断异常：{}", throwable.getMessage());
                return null;
            }

            @Override
            public DataOutDTO<OAuth2ClientBO> getOAuth2ClientById(OAuth2ClientInDTO inDTO) {
                log.error("mall-admin,getOAuth2ClientById 熔断异常：{}", throwable.getMessage());
                return null;
            }
        };
    }
}
